
import 'dart:typed_data';
import 'package:crop_your_image/crop_your_image.dart';
import 'package:dio/dio.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';
import 'package:test01/config/config.dart';


class CropImageRoute extends StatefulWidget {
  var arguments;
  CropImageRoute({Key? key, this.arguments,}) : super(key: key);

  @override
  _CropImageRouteState createState() => _CropImageRouteState();
}


class _CropImageRouteState extends State<CropImageRoute> {
  Uint8List? image; //原始图片路径
  final _controller = CropController();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    image = widget.arguments;
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Container(
            alignment: Alignment.center,
            // width: double.infinity,
            height: 1200.h,
            child: Crop(
                image: image!,
                controller: _controller,
                onCropped: (image) {
                  // do something with image data
                  setState(() {
                    Navigator.pop(context, image);
                  });
                },
                aspectRatio: 4 / 3,
                initialSize: 0.5,
                // initialArea: Rect.fromLTWH(240, 212, 800, 600),
                // withCircleUi: true,
                baseColor: Colors.black45,
                onMoved: (newRect) {
                  // do something with current cropping area.
                },
                onStatusChanged: (status) {
                  // do something with current CropStatus
                },
                cornerDotBuilder: (size, edgeAlignment) => const DotControl(color: Colors.black12),
            ),
          ),
          ElevatedButton(onPressed: () {
            _controller.crop();
          }, child: Text("确定"),style: ElevatedButton.styleFrom(primary: Colors.lightGreen),)
        ],
      ),
    );
  }



}